﻿using System;
using System.Diagnostics;
using Budget.Data.Configs;
using Budget.DataBase;
using NHibernate;
using NHibernate.Cfg;
using Budget.Core.Data;

namespace Budget.Data
{
    public static class DB
    {
        private static ISessionFactory factory;

        public static ISessionFactory Factory
        {
            get { return factory; }
        }

        public static void Init<T>(T config) where T : IConfig<Configuration>
        {
            var configuration = config.GetConfig();
            factory = configuration.BuildSessionFactory();
        }

        public static void Migrate(string db, string con)
        {
            try
            {
                BudgetMigrator.Migrate(db, con);
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.Message);
            }
        }
    }
}